<!--
Author: Quan Van Sinh
Email : sinhvnb@vietnambiz.com
Mobile: 0972405165
-->
<?php include ADMIN_INCLUDE_DIR."/header.php";?>

<script language="javascript" type="text/javascript">
    var popupImageParams = '&forModule=news&position=content';
    $(document).ready(function (){
        CKEDITOR.config.resize_enabled = false;
        CKEDITOR.config.width = 500;
        CKEDITOR.config.height = 400;
        CKEDITOR.replace( 'content',
        {
            toolbar :
                [['Maximize', '-','Format','Font','FontSize','-','TextColor','BGColor','-','Bold','Italic','Underline','Strike','-','NumberedList','BulletedList','-','Outdent','Indent','Blockquote','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock', '-','Image','Table','-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink' ]]
        });

    });

   
    function submitFormAddNews(submitType){
        if(submitType=='exit'){
            $("#submitType").val('exit');
            $("#submitFrmNewsAdd").click();
        }
    }
    function removeImage(id,imageId){
        $("#removeThumb").append('<input type="hidden" name="removeThumb[]" value="'+imageId+'"/>');
        $("#"+id).remove();
    }
    function getGeo(obj,forObj){
        if(obj.value>0){
            $.ajax({
                url: ADMIN_URL+'/index.php',
                type: 'GET',
                data: "module=property&option=geo&action=getGeo&geo=" + obj.value,
                error: function(){
                    alert('Error!');
                },
                success: function(data){
                    if(forObj=='city'){
                        $("#geoCity").html(data);
                        $("#geoDistrict").html('<option value="0">Select geographic...</option>');
                    }else if(forObj=='district'){
                        $("#geoDistrict").html(data);
                    }

                }
            });
        }else{
            $("select[name=geo_id[1]]").html('<option value="0">Select geographic...</option>');
        }
    }
    $(document).ready(function (){
        //get geographic
        $('input[name=geo]').click(function (){
            getGeo(this,'city');
        });
        $("select[name=geo_id]").change(function(){
            getGeo(this,'district');
        });

    });
     function searchAddress(){
        var str=$('#searchMapAddress ').val()+" "+$('#geoDistrict option:selected').text()+" "+$('#geoCity option:selected').text();
        if(str!=' '){           
            showAddress(str);
        }
     }
</script>

<?php $rsNewsEdit = editUpdateNews();?>

<div class="container_l">
    <form name="formNewsAddCategory" method="POST" action="">
        <div class="title_user"><img src="images/icon1.gif" />Dự án</div>
        <div class="table_user">
            <div class="table_user_in2">
                <?php
                show_error();
                show_success();
                ?>
                <fieldset>
                    <legend accesskey="N">Cập nhật dự án</legend>
                    <div class="lineaddnew">
                        <div style="width:70%;float:left;">
                            <div class="lineform">
                                <div class="divlabel_news">Tiêu đề: <font color="#FF0000">*</font></div>
                                <div class="divform">
                                    <input type="hidden" name="id" value="<?php echo $rsNewsEdit['rsNewsEdit']['id'];?>"/>
                                    <input type="text" name="title" value="<?php echo htmlentities($rsNewsEdit['rsNewsEdit']['title'], ENT_COMPAT, 'UTF-8');?>"/>
                                </div>
                            </div>
                            <div class="lineform">
                                <div class="divlabel_news">Danh mục: <font color="#FF0000">*</font></div>
                                <div class="divform">
                                    <select name="cat_id">
                                        <?php
                                        $arrNewsCat = listAllNewsCategory($parent_id = 0);
                                        for($i=0;$i<count($arrNewsCat);$i++) {
                                            ?>
                                        <option <?php echo setSelectedBoxValue($rsNewsEdit['rsNewsEdit']['cat_id'], $arrNewsCat[$i]['cat_id']);?> value="<?php echo $arrNewsCat[$i]['cat_id'];?>"><?php echo $arrNewsCat[$i]['cat_title'];?></option>
                                            <?php
                                        }
                                        ?>
                                    </select>
                                </div>
                            </div>
                            <div class="lineform">
                                <div class="divlabel_news">VT địa lý: <font color="#FF0000">*</font></div>
                                <div style="margin-top:6px;margin-left:115px;">
                                    <?php
                                    $rsGrandCity = getProjectsGeographicGrandParent($rsNewsEdit['rsNewsEdit']['geo_id']);
                                    if($rsGrandCity['geo_parent']==0) {
                                        $geoRootId = 1;
                                    }else {
                                        $geoRootId = $rsGrandCity['geo_parent'];
                                    }
                                    ?>
                                    <label><input type="radio" name="geo" value="1" <?php echo setCheckedBoxValue($geoRootId,'1',true);?> /> Miền bắc</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <label><input type="radio" name="geo" value="2" <?php echo setCheckedBoxValue($geoRootId,'2');?> /> Miền trung</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <label><input type="radio" name="geo" value="3" <?php echo setCheckedBoxValue($geoRootId,'3');?> /> Miền nam</label>
                                    <br>Thành phố:&nbsp;&nbsp;&nbsp;&nbsp; <select id="geoCity" onchange="showAddress($('#geoCity option:selected').text());" name="geo_id" style="margin-top:5px;width:350px">
                                        <?php
                                            $arrGeoCity = listAllPropertyGeographicByParent($geoRootId);
                                            echo '<option value="0">Chọn thành phố...</option>';
                                            for($i=0;$i<count($arrGeoCity);$i++) {
                                                echo '<option '.setSelectedBoxValue($rsNewsEdit['rsNewsEdit']['geo_id'], $arrGeoCity[$i]['geo_id']).' value="'.$arrGeoCity[$i]['geo_id'].'">'.$arrGeoCity[$i]['geo_title'].'</option>';
                                            }
                                        ?>
                                    </select>
                                    <br>Quận/Huyện:&nbsp;&nbsp;<select id="geoDistrict" onchange="showAddress($('#geoDistrict option:selected').text()+' '+$('#geoCity option:selected').text());" style="margin-top:5px;width:350px">
                                        <?php
                                        if(isset($rsNewsEdit['rsNewsEdit']['geo_id']) && intval($rsNewsEdit['rsNewsEdit']['geo_id'])>0) {
                                            $arrGeoDistrict = listAllPropertyGeographicByParent($rsNewsEdit['rsNewsEdit']['geo_id']);
                                            echo '<option value="0">Chọn quận/huyện...</option>';
                                            for($i=0;$i<count($arrGeoDistrict);$i++) {
                                                echo '<option '.setSelectedBoxValue($arrGeoId[1], $arrGeoDistrict[$i]['geo_id']).' value="'.$arrGeoDistrict[$i]['geo_id'].'">'.$arrGeoDistrict[$i]['geo_title'].'</option>';
                                            }
                                        }else {
                                            echo '<option value="0">Chọn quận/huyện...</option>';
                                        }
                                        ?>
                                    </select>
                                    <br>Tên đường/Địa điểm:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="searchMapAddress" onkeydown="if (event.keyCode == 13){searchAddress();return false;}"  style="margin-top:5px;width:272px"/> <input type="button" onclick="searchAddress();" value="Định vị"/>
                                    <div style="margin-left: 153px;">VD: thap rua, hoang quoc viet, hoc vien tai chinh, duong truong chinh...</div>
                                </div>
                            </div>
                            <div class="lineform">
                                <div class="divlabel_news">Bản đồ:</div>
                                <div class="divform">
                                    <input type="text" id="geocodeRoboGEO" name="map" value="<?php echo $rsNewsEdit['rsNewsEdit']['map'];?>" style="width: 235px;margin-bottom: 5px;display: none;" readonly/>
                                    <div id="map" style="width: 600px; height: 400px"></div>
                                    <script type="text/javascript">
<?php
$arrMap = explode(',', $rsNewsEdit['rsNewsEdit']['map']);
$arrMapLat = explode(':', $arrMap[0]);
$arrMapLon = explode(':', $arrMap[1]);
;?>
    $(document).ready(function (){
        load();
    });
    $(document).unload(function (){
        GUnload();
    });
    function load() {
        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map"));
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            var center = new GLatLng(
<?php if($arrMapLat[1]!='') {
    echo $arrMapLat[1];
} else {
    echo '21.028711';
}?>,  	<?php if($arrMapLon[1]!='') {
    echo $arrMapLon[1];
} else {
    echo '105.852456';
}?>);
            map.setCenter(center, 15);
            geocoder = new GClientGeocoder();
            var marker = new GMarker(center, {draggable: true});
            map.addOverlay(marker);
            var message = 'latitude: ' + center.lat().toFixed(5) + ', longitude: ' + center.lng().toFixed(5);
            document.getElementById("geocodeRoboGEO").value = message;
            //document.getElementById("lat").innerHTML = center.lat().toFixed(5);
            //document.getElementById("lng").innerHTML = center.lng().toFixed(5);
            GEvent.addListener(marker, "dragend", function() {
                var point = marker.getPoint();
                map.panTo(point);
                var message = 'latitude: ' + point.lat().toFixed(5) + ', longitude: ' + point.lng().toFixed(5);
                document.getElementById("geocodeRoboGEO").value = message;
                //document.getElementById("lat").innerHTML = point.lat().toFixed(5);
                //document.getElementById("lng").innerHTML = point.lng().toFixed(5);
            });
            GEvent.addListener(map, "moveend", function() {
                map.clearOverlays();
                var center = map.getCenter();
                var marker = new GMarker(center, {draggable: true});
                map.addOverlay(marker);
                var message = 'latitude: ' + center.lat().toFixed(5) + ', longitude: ' + center.lng().toFixed(5);
                document.getElementById("geocodeRoboGEO").value = message;
                //document.getElementById("lat").innerHTML = center.lat().toFixed(5);
                //document.getElementById("lng").innerHTML = center.lng().toFixed(5);
                GEvent.addListener(marker, "dragend", function() {
                    var point =marker.getPoint();
                    map.panTo(point);
                    var message = 'latitude: ' + point.lat().toFixed(5) + ', longitude: ' + point.lng().toFixed(5);
                    document.getElementById("geocodeRoboGEO").value = message;
                    //document.getElementById("lat").innerHTML = point.lat().toFixed(5);
                    //document.getElementById("lng").innerHTML = point.lng().toFixed(5);
                });
            });
        }
    }
    function findAddress() {
        myAddress = document.getElementById("address").value;
        geocoder.getLocations(myAddress, getCoordForAddress);
    }
 
                                    </script>
                                </div>
                            </div>
                            <div class="lineform">
                                <div class="divlabel_news">Chủ đầu tư:</div>
                                <div class="divform">
                                    <input type="text" id="chudautu" name="chudautu" value="<?php echo htmlentities($rsNewsEdit['rsNewsEdit']['chudautu'], ENT_QUOTES, 'UTF-8');?>" style="width:99%;"/>
                                </div>
                            </div>
                            <div class="lineform">
                                <div class="divlabel_news">Đơn vị tư vấn:</div>
                                <div class="divform">
                                    <input type="text" id="donvituvan" name="donvituvan" value="<?php echo htmlentities($rsNewsEdit['rsNewsEdit']['donvituvan'], ENT_QUOTES, 'UTF-8');?>" style="width:99%;"/>
                                </div>
                            </div>
                            <div class="lineform">
                                <div class="divlabel_news">ĐV thi công:</div>
                                <div class="divform">
                                    <input type="text" id="donvithicong" name="donvithicong" value="<?php echo htmlentities($rsNewsEdit['rsNewsEdit']['donvithicong'], ENT_QUOTES, 'UTF-8');?>" style="width:99%;"/>
                                </div>
                            </div>
                            <div class="lineform">
                                <div class="divlabel_news">Tổng đầu tư:</div>
                                <div class="divform">
                                    <input type="text" id="tongdautu" name="tongdautu" value="<?php echo htmlentities($rsNewsEdit['rsNewsEdit']['tongdautu'], ENT_QUOTES, 'UTF-8');?>" style="width:99%;"/>
                                </div>
                            </div>
                            <div class="lineform">
                                <div class="divlabel_news">Diện tích:</div>
                                <div class="divform">
                                    <input type="text" id="dientich" name="dientich" value="<?php echo htmlentities($rsNewsEdit['rsNewsEdit']['dientich'], ENT_QUOTES, 'UTF-8');?>" style="width:99%;"/>
                                </div>
                            </div>
                            <div class="lineform">
                                <div class="divlabel_news">Ngày khởi công:</div>
                                <div class="divform">
                                    <input type="text" onclick="return showCalendar('ngaykhoicong');" id="ngaykhoicong" name="ngaykhoicong" value="<?php echo htmlentities($rsNewsEdit['rsNewsEdit']['ngaykhoicong'], ENT_QUOTES, 'UTF-8');?>" style="width:45%;"/>
                                    <img src="<?php echo ADMIN_IMAGES_URL;?>/calendar.png" onclick="return showCalendar('ngaykhoicong');">
                                </div>
                            </div>

                            <div class="lineform">
                                <div class="divlabel_news">Ngày hoàn thành:</div>
                                <div class="divform">
                                    <input type="text" onclick="return showCalendar('ngayhoanthanh');" id="ngayhoanthanh" name="ngayhoanthanh" value="<?php echo htmlentities($rsNewsEdit['rsNewsEdit']['ngayhoanthanh'], ENT_QUOTES, 'UTF-8');?>" style="width:45%;"/>
                                    <img src="<?php echo ADMIN_IMAGES_URL;?>/calendar.png" onclick="return showCalendar('ngayhoanthanh');">
                                </div>

                            </div>
                            <div class="lineform">
                                <div class="divlabel_news">Thư viện ảnh:</div>
                                <div class="divform" style="width:75%;">
                                    <div style="float:left;width:100%;">
                                        <div><input type="button" value="Chọn ảnh" onclick="popupImages('&forModule=projects');" class="button" style="width:100px;" /><div style="padding-top:8px">&nbsp;&nbsp;&nbsp;&nbsp;Ảnh đầu tiên sẽ được dùng làm ảnh hiển thị.</div></div>
                                    </div>
                                    <div id="removeThumb"></div>
                                    <div id="propertyImagesThumb">
                                        <?php
                                        while($rs=$db->fetch_array($rsNewsEdit['rsProjectsImage'])) {
                                            $randomHtmlId = rand(9999, 999999999);
                                            ?>
                                        <div id="<?php echo $randomHtmlId;?>">
                                            <input type="hidden" value="<?php echo $rs['id'];?>" name="thumb[]"/>
                                            <img alt="" style="border: 3px solid rgb(204, 204, 204); float: left; margin-right: 5px; margin-top: 5px; width: 87px; height: 87px;" src="<?php echo $rs['image'];?>" id="imgDisplay"/>
                                            <a href="javascript:removeImage('<?php echo $randomHtmlId;?>','<?php echo $rs['id'];?>');" class="removeImage" title="Xóa ảnh này"></a>
                                        </div>
                                            <?php
                                        }
                                        ?>
                                    </div>
                                </div>
                            </div>
                            <div class="lineform">
                                <div class="divlabel_news">Mô tả: <font color="#FF0000">*</font></div>
                                <div class="divform"><textarea id="description" name="description" cols="10" rows="10" style="overflow:hidden;width:99%;"><?php echo $rsNewsEdit['rsNewsEdit']['description'];?></textarea></div>
                            </div>
                            <div class="lineform">

                                <div class="lineform">
                                    <div class="divlabel_news">Nội dung: <font color="#FF0000">*</font></div>
                                    <div style="margin-left:16%;">
                                        <textarea name="content" id="content" cols="2" rows="10"><?php echo $rsNewsEdit['rsNewsEdit']['content'];?></textarea>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="spacer1"><span></span></div>
                </fieldset>
                <div class="linesubmit">
                    <input type="hidden" name="submitType" id="submitType" value="">
                    <input type="submit" name="submitFrmNewsAdd" id="submitFrmNewsAdd" value="Lưu lại" class="button" />
                    <input type="button" name="submitFrmNewsAddAndExit" onclick="document.location='?module=prọects'" value="Thoát" class="button" />
                </div>
            </div>
        </div>
    </form>
</div>
<?php
include "inc/right.php";
include ADMIN_INCLUDE_DIR."/footer.php";
?>